

from selenium.webdriver.chrome import webdriver
from selenium.webdriver.common.by import By

from common.doLog import DoLog

logger = DoLog().set_get_logger()

class ShoppCar():
    addCar1=(By.CSS_SELECTOR,".btn_pink_138x32")
    cleanCar=(By.XPATH,"//*[@type='button']")
    electShopp = (By.XPATH, "//*[@alt='漫步者008' and @class='B_blue']")
    addCar2 = (By.CSS_SELECTOR, ".btn_pink_138x32")
    refleshCar = (By.XPATH, "//*[@name='submit' and @class='bnt_blue_1']")


    def shopp(self):
        login = webdriver.WebDriver()
        login.get("http://192.168.40.130/goods.php?id=142")
        login.implicitly_wait(10)

        try:
            logger.info("---运算开始了---")
            login.find_element(*self.addCar1).click()
            login.find_element(*self.cleanCar).click()
            login.find_element(*self.electShopp).click()
            login.find_element(*self.addCar2).click()
            login.find_element(*self.refleshCar).click()
        except Exception as e:
             logger.error(f"出现异常，异常是：{e}")
        else:
            logger.info("---运算顺利完成---")
        finally:
            logger.info("运算结束------")


if __name__ == '__main__':
    shopping=ShoppCar()
    shopping.shopp()
